Skip to main content

Traverse the Rows of the Datagrid and Access Its Cells with Code on the Flow Side

Required libraries:

using Bimser.Synergy.Entities.Workflow.EventArguments; using System; using Bimser.CSP.Runtime.Common.Extensions; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using Bimser.Synergy.ServiceAPI.Models.Form; using Bimser.Synergy.Entities.Shared.Business.Objects;

Function1 object Execute event:

public void Function1_Execute(object sender,OnExecuteEventArguments args) { Control gridControl = Document1.Controls["DataGrid1"]; datagrid is assigned to a variable of type Control.

Reaching cells with their indices

GridData dataGrid1 = GridData.FromControl(gridControl); The control variable should be taken as GridData.

var grid1Rows = dataGrid1.Rows; All rows in the datagrid are captured. foreach(var row in grid1Rows) //rows are looped. { LogExtension.Log(row. Cells[1]?. Value,args. Context); 1.Writes the Value value of the indexed cell to the console. LogExtension.Log(row. Cells[1]?. Text,args. Context); Writes the Text value of the 1st indexed cell to the console. }

Reach cells by name

var Jgrid1Rows = gridControl.Value as JArray; The Value value of the control variable is retrieved as a JSON array. foreach(var jRow in Jgrid1Rows) //Rows with JSON arrays are looped. { JObject joRow = JObject.Parse(jRow.ToString()); The JSON string containing the row's data is converted to a JObject object and assigned to the joRow variable. LogExtension.Log(joRow.SelectToken("$.. cells[?( @.name == 'Kolon1')].value")?. ToString(),args. Context); Writes the Value value of the cell named Column1 to the console as a string. } }